package ua.org.nuos.sdms.middle.service;

import ua.org.nuos.sdms.middle.entity.User;
import ua.org.nuos.sdms.middle.entity.enums.Role;
import ua.org.nuos.sdms.middle.util.exception.DuplicateEmailException;
import ua.org.nuos.sdms.middle.util.exception.OneGroupLeaderException;

import javax.annotation.security.RolesAllowed;
import javax.ejb.Local;
import java.util.List;

/**
 * User: Denis Fahritdinov
 * Date: 10/7/12
 * Time: 11:53 AM
 */
@Local
public interface UserServiceLocal {

    /**
     * Update existing user
     * password does not changed
     *
     * @param user
     * @throws DuplicateEmailException
     */
    void updateCurrentUser(User user) throws DuplicateEmailException;

    /**
     * Change user password
     *
     * @param password
     */
    void changeCurrentUserPassword(String password);

    /**
     * Find user by id
     *
     * @param userId
     * @return
     */
    User findUserById(long userId);

    /**
     * Find user by email
     *
     * @param userEmail
     * @return
     */
    User findUserByEmail(String userEmail);

    /**
     * Find user by name
     *
     * @param name
     * @return
     */
    List<User> listUsersByName(String name);

    /**
     * Find users in group
     *
     * @param groupId
     * @return
     */
    List<User> listUsersByGroup(long groupId);

    /**
     * Remove user
     */
    void removeCurrentUser() throws OneGroupLeaderException;

    /**
     * Add role to user
     *
     * @param userId
     * @param role
     */
    void addRole(long userId, Role role);

    /**
     * Remove role from user
     *
     * @param userId
     * @param role
     */
    void removeRole(long userId, Role role);

    /**
     * Remove all user roles
     *
     * @param userId
     */
    void removeAllRoles(long userId);

    /**
     * Check if user can be in role
     *
     * @param userId
     * @param role
     * @return
     */
    boolean canUserBeInRole(long userId, Role role);

    /**
     * Check if current user can be in role
     *
     * @param role
     * @return
     */
    boolean canCurrentUserBeInRole(Role role);

    /**
     * List user roles
     *
     * @return
     */
    List<Role> listUserRoles();
}
